package kth;

import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * Tests that the formula used to generate the firing power returns the expected
 * results when given near-boundary values.
 * 
 * @author Kim
 *
 */
public class TestCalculateFirePower {
  // Initialize variables to the standard values for a Robocode battle
  double minPower = 0.1; // The robot's minimum firing power
  double maxPower = 3.0; // The robot's maximum firing power
  double maxDist = 1000; // The typical maximum distance between robots
  
  /**
   * Tests that the robot will use a high firing power when the distance from the enemy
   * is small.
   */
  @Test
  public void testNearCalculation() {
    assertTrue("Near robot generates high fire power", calculateFirePower(20) > 2.8);
  }
  
  /**
   * Tests that the robot will use a low firing power when the distance from the enemy
   * is great.
   */
  @Test
  public void testFarCalculation() {
    assertTrue("Far robot generates lower fire power", calculateFirePower(980) < 0.3);
  }
  
  /**
   * Calculates the firing power to be used. Is the same function as that given in
   * PacerEvader's definition.
   * 
   * @param d the distance from the enemy.
   * @return The power to be used when firing.
   */
  public double calculateFirePower(double d) {
    return minPower + (maxDist - d) / maxDist * (maxPower - minPower);
  }
}
